package org.onionframework.persistence.dao.expression;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.onionframework.persistence.query.DatePart;

public class OnionExpressions {

	public static HasExpression has(String propertyName,Criteria father){
		return new HasExpression(propertyName, father);
	}
	
	public static NotHasExpression notHas(String propertyName,Criteria father){
		return new NotHasExpression(propertyName, father);
	}
	
	public static DateStringExpression dateStringEq(String propertyName,String value,String pattern){
		return new DateStringExpression(propertyName, value, "=", pattern);
	}
	
	public static DateStringExpression dateStringLike(String propertyName,String value,String pattern){
		return new DateStringExpression(propertyName, value, "like", pattern);
	}
	
	public static DatePartExpression datePartEq(String propertyName,Integer value, DatePart datePart){
		return new DatePartExpression(propertyName, value, "=", datePart);
	}
	
	public static DatePartExpression datePartLe(String propertyName,Integer value, DatePart datePart){
		return new DatePartExpression(propertyName, value, "<=", datePart);
	}
	
	public static DatePartExpression datePartLt(String propertyName,Integer value, DatePart datePart){
		return new DatePartExpression(propertyName, value, "<", datePart);
	}
	
	public static DatePartExpression datePartGe(String propertyName,Integer value, DatePart datePart){
		return new DatePartExpression(propertyName, value, ">=", datePart);
	}
	
	public static DatePartExpression datePartGt(String propertyName,Integer value, DatePart datePart){
		return new DatePartExpression(propertyName, value, ">", datePart);
	}
	
	public static EscapedLikeExpression like(String propertyName,String value, MatchMode matchMode){
		return new EscapedLikeExpression(propertyName,matchMode.toMatchString(value));
	}
	
	public static EscapedLikeExpression ilike(String propertyName,String value, MatchMode matchMode){
		return new EscapedLikeExpression(propertyName,matchMode.toMatchString(value),true);
	}
}
